package com.example.sample.slice;

import com.example.sample.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Text;

public class MainAbilitySlice extends AbilitySlice {

    private Text mResult;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_test_volley_layout);
//        mResult = (Text) findComponentById(ResourceTable.Id_test_get_result);
        Button testVolleyGet = (Button) findComponentById(ResourceTable.Id_test_get);
        testVolleyGet.setClickable(true);
        testVolleyGet.setEnabled(true);
        testVolleyGet.setClickedListener(component -> testVolleyGet());
    }

    private void testVolleyGet() {
        Intent intent = new Intent();
        // 通过 Intent 中的 OperationBuilder 类构造 operation 对象，指定设备标识（空串表示当前设备）、应用包名、Ability 名称
        Operation operation = new Intent.OperationBuilder()
                .withDeviceId("")
                .withBundleName("com.example.sample")
                .withAbilityName("com.example.sample.TestVolleyGetAbility")
                .build();
        // 把 operation 设置到 intent 中
        intent.setOperation(operation);
        startAbility(intent);
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
